package operation;

import result.ScoreList;

import java.util.Scanner;

public class SortOperation implements IOperation{
    @Override
    public void work(ScoreList scoreList) {
        System.out.println("排序成绩!!!!");
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要排序的科目:");
        String courseName=sc.nextLine();
        int size=scoreList.getSize();
        int score[]=new int[size];
        for(int i=0;i<size;i++){
            if(scoreList.getScores(i).getCourseName().equals(courseName)){
                score[i]=scoreList.getScores(i).getScore();
            }
        }
        for(int i=0;i<size-1;i++){
            for(int j=i+1;j<size;j++){
                if(score[i]<score[j]){
                    int temp=score[i];
                    score[i]=score[j];
                    score[j]=temp;
                }
            }
        }
        System.out.println("排序后的成绩为:");
        for(int i=0;i<size;i++){
            System.out.print(score[i]+" ");
        }
        System.out.println();
    }
}
